import axios from "axios";

export function request(config) {
  const instance = axios.create({
    baseURL: "http://116.62.145.164:8081",
    timeout: 10000,
  });

  //拦截器
  instance.interceptors.request.use(
    (confing) => {
      let token = window.localStorage.getItem("accessToken")
    if (token) {
        //将token放到请求头发送给服务器,将tokenkey放在请求头中
        config.headers.accessToken = token;     
        //也可以这种写法
        // config.headers['accessToken'] = Token;
         return config;
    }
      console.log(confing);
      return confing;
    },
    (err) => {
      console.log(err);
    }
  );

  //返回数据
  return instance(config);
}
